﻿using FluentNHibernate.Mapping;
using ScriptManager.Data.Domain.Entities;

namespace ScriptManager.Data.Domain.Mapping
{
    public class ScriptRevisionMap : ClassMap<ScriptRevision>
    {
        public ScriptRevisionMap()
        {
            Id( m => m.ID ).GeneratedBy.Identity();
         
            Map( m => m.Text );
            Map( m => m.Version ).WithLengthOf( 10 ); 
            Map( m => m.DBVersion ).WithLengthOf( 10 ); 
            Map( m => m.LongDescription ).WithLengthOf( 200 ); 
            Map( m => m.Date );

            References<Author>( m => m.Author, "AuthorID" );
            References<Script>( m => m.Script, "ScriptID" );

            //Learn how the below works, read up on fluent mappings

            //References<User>(r => r.Author, "AuthorID")
            //    .Cascade.SaveUpdate()
            //    .FetchType.Join();

            //References<User>(r => r.LastModifiedBy, "LastModifiedAuthorID")
            //    .Cascade.SaveUpdate()
            //    .FetchType.Join();

            //HasMany<Tag>(r => r.Tags)
            //    .WithKeyColumn("RecipeID")
            //    .Cascade.AllDeleteOrphan();

            //HasMany<Section>(r => r.Sections)
            //    .WithKeyColumn("RecipeID")
            //    .Cascade.AllDeleteOrphan();
        }
    }
}